import request from '@/utils/request'

// 设备看板API
export function getDashboardData() {
  return request({
    url: '/smart/device/dashboard/data',
    method: 'get'
  })
}

// 设备状态API
export function getDeviceStatusList() {
  return request({
    url: '/smart/device/status/list',
    method: 'get'
  })
}

export function getDeviceStatus(deviceId) {
  return request({
    url: `/smart/device/status/${deviceId}`,
    method: 'get'
  })
}

export function getDeviceStatistics() {
  return request({
    url: '/smart/device/status/statistics',
    method: 'get'
  })
}

export function getDeviceLastActive(deviceId) {
  return request({
    url: `/smart/device/status/lastActive/${deviceId}`,
    method: 'get'
  })
}

export function removeDevice(deviceId) {
  return request({
    url: `/smart/device/status/${deviceId}`,
    method: 'delete'
  })
}

export function cleanupExpiredDevices(expiryTime) {
  return request({
    url: '/smart/device/status/cleanup',
    method: 'post',
    params: { expiryTime }
  })
}

// 设备控制API
export function sendDeviceCommand(deviceId, command) {
  return request({
    url: `/smart/device/control/command/${deviceId}`,
    method: 'post',
    data: command
  })
}

export function batchSendDeviceCommand(deviceCommands) {
  return request({
    url: '/smart/device/control/batchCommand',
    method: 'post',
    data: deviceCommands
  })
}

export function batchSendByType(deviceType, command) {
  return request({
    url: `/smart/device/control/batchByType/${deviceType}`,
    method: 'post',
    data: command
  })
}

export function batchSendByStatus(online, command) {
  return request({
    url: `/smart/device/control/batchByStatus/${online}`,
    method: 'post',
    data: command
  })
}

export function getControlHistory(deviceId, limit = 10) {
  return request({
    url: `/smart/device/control/history/${deviceId}`,
    method: 'get',
    params: { limit }
  })
}
